import Vue from 'vue';
import VueRouter from 'vue-router';
import Test from '../components/Test.vue';
import Index from '../views/comic/Index.vue';
import IndexMainChief from '../views/comic/IndexMainChief.vue';
import ComicInfo from '../views/comic/ComicInfo.vue';
import ComicBrowse from '../views/comic/ComicBrowse.vue';
import ComicCatalog from '../views/comic/ComicCatalog.vue';
import ComicResult from '../views/comic/ComicResult.vue';
import ComicClassify from '../views/comic/ComicClassify.vue';
import ComicCellPage from '../views/comic/ComicCellPage.vue';
import Login from '../views/user/Login.vue';
import UserInfo from '../views/user/UserInfo.vue';




Vue.use(VueRouter);

const routes = [
  { path: '/', redirect: '/index' },
  { path: '/test', name: 'test', component: Test },
  {
    path: '/index',
    name: 'index',
    component: Index,
    children: [
      { path: '/indexMainChief', name: 'indexMainChief', component: IndexMainChief }
    ]
  },
  { path: '/comicInfo', name: 'comicInfo', component: ComicInfo },
  { path: '/comicBrowse', name: 'comicBrowse', component: ComicBrowse },
  { path: '/comicCatalog', name: 'comicCatalog', component: ComicCatalog },
  { path: '/comicResult', name: 'comicResult', component: ComicResult },
  { path: '/comicClassify', name: 'comicClassify', component: ComicClassify },
  { path: '/comicCellPage', name: 'comicCellPage', component: ComicCellPage },
  { path: '/login', name: 'login', component: Login },
  { path: '/userInfo', name: 'userInfo', component: UserInfo }
];
// 路由地址重复解决方案
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err);
};

// routes.beforeEach((to, from, next) => {
//   // console.log(Vue.$cookies);
//   const valib = Vue.$cookies.get('token');
//   if (to.path === '/login') return next();
//   if (valib == null) return next('/login');
//   if (!valib) return next('/login');
//   next();
// });
const router = new VueRouter({
  routes
});

export default router;
